Page({
  data: {
		moId:'',
		seeTxt:[
			{
				tlt:'活动访问用户数',
				name:'openHomePageCount',
        as:'openHomePageCountDayAddRate',
        tips:"打开应用的总人数"
			},
			{
				tlt:'签到用户数',
				name:'openHomePagePeopleCount',
        as:'openHomePagePeopleCountDayAddRate',
        tips:"签到用户总人数"
			},
			{
				tlt:'订阅店铺用户数',
				name:'followCount',
        as:'followCountDayAddRate',
        tips:"关注店铺的总人数"
			},
			{
				tlt:'入会用户数',
				name:'membershipCount',
        as:'membershipCountDayAddRate',
        tips:"加入会员的总人数"
			},
			{
				tlt:'浏览商品用户数',
				name:'openHomePageCount',
        as:'browseProductCountDayAddRate',
        tips:"商品浏览的总次数"
			},
			{
				tlt:'活动参与用户数',
				name:'playGameCount',
        as:'playGameCountDayAddRate',
        tips:"游戏PK的总局数"
      },
      // {
			// 	tlt:'分享回流用户数',
			// 	name:'shareCount',
      //   as:'shareCountDayAddRate',
      //   tips:"活动分享的总次数"
			// },
			// {
			// 	tlt:'收藏商品数',
			// 	name:'collectProductCount',
      //   as:'collectProductCountDayAddRate',
      //   tips:"所有商品收藏的总次数"
      // },
      // {
			// 	tlt:'会员UV',
			// 	name:'openHomePageForMemberPeopleCount',
      //   as:'openHomePageForMemberPeopleCountDayAddRate',
      //   tips:"会员用户打开应用的总人数"
      // }
		],

		seeData:"",

    idx:0,
    option:[],
    appidd:""

	},

	//请求埋点数据
	reqSeeData(){

    let o={
      activityId:this.data.activityId,
      endDate: this.data.endDate,
      startDate:this.data.startDate
    }

    console.log("条件=====",o)

		getApp().cloud.application.httpRequest({
      'path' : '/api/b/userData/getDataCount', 
      'method':'POST',
      'headers':{ "Content-Type":"application/json"},
      'body':o,
    }).then(res => {
			console.info('埋点数据请求结果=====》',res)
			
			this.setData({
				seeData:res.data
      })
      

		})

	},

	//获取活动列表
	// activityList(){
	// 	getApp().cloud.application.httpRequest({
  //     'path' : 'api/b/getActionList', 
  //     'method':'POST',
	// 		'headers':{ "Content-Type":"application/json"},
  //     'body':{
	// 			pageNo:1,
	// 			pageSize:1000
	// 		},
  //   }).then(res => {
	// 		console.info('活动列表=====》',res.data.list)

	// 		if(res.code != 200)return

	// 		this.setData({
	// 			list:res.data.list,
	// 			moId:res.data.list[0].id
	// 		})

	// 		// let o = {
	// 		// 	activityId:res.data.list[0].id
  //     // }
      

  //     //查询列表获取第一条信息  渲染第一条活动的所有数据
  //     this.setData({
  //       activityId:res.data.list[0].id
  //     })

  //     this.reqSeeData();
			
	// 	})
  // },

  //判断活动的
  orderLevel(i){

    //console.log(i)

    if(i == 1){
      //日常
      let seeTxt=[
        {
          tlt:'活动访问用户数',
          name:'openHomePageCount',
          as:'openHomePageCountDayAddRate',
          tips:"打开应用的总人数"
        },
        {
          tlt:'签到用户数',
          name:'openHomePagePeopleCount',
          as:'openHomePagePeopleCountDayAddRate',
          tips:"签到用户总人数"
        },
        {
          tlt:'订阅店铺用户数',
          name:'followCount',
          as:'followCountDayAddRate',
          tips:"关注店铺的总人数"
        },
        {
          tlt:'入会用户数',
          name:'membershipCount',
          as:'membershipCountDayAddRate',
          tips:"加入会员的总人数"
        },
        {
          tlt:'浏览商品用户数',
          name:'openHomePageCount',
          as:'browseProductCountDayAddRate',
          tips:"商品浏览的总次数"
        },
        {
          tlt:'活动参与用户数',
          name:'playGameCount',
          as:'playGameCountDayAddRate',
          tips:"游戏PK的总局数"
        }
      ]

      this.setData({
        seeTxt:seeTxt
      })
      

    }else if(i == 3){
      //大促(三个都有)
      let seeTxt=[
        {
          tlt:'活动访问用户数',
          name:'openHomePageCount',
          as:'openHomePageCountDayAddRate',
          tips:"打开应用的总人数"
        },
        {
          tlt:'签到用户数',
          name:'openHomePagePeopleCount',
          as:'openHomePagePeopleCountDayAddRate',
          tips:"签到用户总人数"
        },
        {
          tlt:'订阅店铺用户数',
          name:'followCount',
          as:'followCountDayAddRate',
          tips:"关注店铺的总人数"
        },
        {
          tlt:'入会用户数',
          name:'membershipCount',
          as:'membershipCountDayAddRate',
          tips:"加入会员的总人数"
        },
        {
          tlt:'浏览商品用户数',
          name:'openHomePageCount',
          as:'browseProductCountDayAddRate',
          tips:"商品浏览的总次数"
        },
        {
          tlt:'活动参与用户数',
          name:'playGameCount',
          as:'playGameCountDayAddRate',
          tips:"游戏PK的总局数"
        },
        {
          tlt:'分享回流用户数',
          name:'shareCount',
          as:'shareCountDayAddRate',
          tips:"活动分享的总次数"
        },
        {
          tlt:'收藏商品数',
          name:'collectProductCount',
          as:'collectProductCountDayAddRate',
          tips:"所有商品收藏的总次数"
        }
      ]

      this.setData({
        seeTxt:seeTxt
      })
      
      // this.seeData({
      //   seeTxt:this.data.seeTxt.concat(dc)
      // })

    }else if(i == 4){
      //会员运营（只有会员运营）
      let seeTxt=[
        {
          tlt:'活动访问用户数',
          name:'openHomePageCount',
          as:'openHomePageCountDayAddRate',
          tips:"打开应用的总人数"
        },
        {
          tlt:'签到用户数',
          name:'openHomePagePeopleCount',
          as:'openHomePagePeopleCountDayAddRate',
          tips:"签到用户总人数"
        },
        {
          tlt:'订阅店铺用户数',
          name:'followCount',
          as:'followCountDayAddRate',
          tips:"关注店铺的总人数"
        },
        {
          tlt:'入会用户数',
          name:'membershipCount',
          as:'membershipCountDayAddRate',
          tips:"加入会员的总人数"
        },
        {
          tlt:'浏览商品用户数',
          name:'openHomePageCount',
          as:'browseProductCountDayAddRate',
          tips:"商品浏览的总次数"
        },
        {
          tlt:'活动参与用户数',
          name:'playGameCount',
          as:'playGameCountDayAddRate',
          tips:"游戏PK的总局数"
        },
        {
          tlt:'会员UV',
          name:'openHomePageForMemberPeopleCount',
          as:'openHomePageForMemberPeopleCountDayAddRate',
          tips:"会员用户打开应用的总人数"
        }
      ]

      this.setData({
        seeTxt:seeTxt
      })
    
      // this.seeData({
      //   seeTxt:this.data.seeTxt.concat(member)
      // })

    }
    
  },

  
  //获取活动下拉列表
  getActiveLise(dataSeeId){
    getApp().cloud.application.httpRequest({
      'path' : '/api/b/getAppName', 
      'method':'GET',
			'headers':{ "Content-Type":"application/json"},
      'body':{},
    }).then(res => {

      this.setData({
        option:res.data
      })

      for(let i in res.data){
        if(res.data[i].id == dataSeeId){
          this.setData({
            option:res.data,
            dataSeeName:res.data[i].title,
            activityId:res.data[i].id
          })
        }
      }
 

      console.log("活动列表",res)

		})
  },

	selectChange(e){

    let idx = e.detail.value;

		this.setData({
      idx:idx,
    })
    
    for(let i in this.data.option){
      if(this.data.option[i].id==idx){
        this.setData({
          appidd:this.data.option[i].miniappId,
          activityId:e.detail.value,
          dataSeeName:this.data.option[i].title
        })

        //console.log("orderLevel-=========>",this.data.option[i].orderLevel)

        //this.reqSeeData();
        this.orderLevel(this.data.option[i].orderLevel);

      }
    }
    
    console.info("111221132131",this.data.appidd)
    
  },


  

	dateChange(e){

    //console.log("=======时间=====>",e.detail.value)

		let start = e.detail.value;

    let end = e.detail.value.substr(0,10) + ' 23:59:59'
    
    //console.log("1111111",this.data.list[this.data.idx].id)

		// let o = {
		// 	activityId:this.data.list[this.data.idx].id,
		// 	endDate: end,
    //   startDate:start,
    // }
    
    this.setData({
      endDate: end,
      startDate:start,
    })

    //this.reqSeeData(o)
    
    // =========>活动id为空

  },
  
  jumpgfkb(){

    if(this.data.appidd){
      let link=`https://console-snipcode.taobao.com/miniapp/data/board#/?appId=${this.data.appidd}`;
      // my.navigateTo({
      // 	url: `../webView/webView?url=${link}`
      // });
      my.qn.navigateToWebPage({
        url: link,
        success: res => {
        },
        fail: res => {
        }
      });
    }else{
      my.showToast({
        content:'请先选择活动'
      });
    }

  },

	onLoad(query) {

    // this.getActiveLise();

    console.log("shu==========",query);

    if(query.miniappId){
      this.setData({
        appidd:query.miniappId
      })
    }

    if(query.id){

      this.setData({
        dataSeeId:query.id
      })

      this.getActiveLise(query.id);

      let o={
        activityId:query.id,
        endDate: this.data.endDate,
        startDate:this.data.startDate
      }

      console.log("条件=====",o)
      
      getApp().cloud.application.httpRequest({
        'path' : '/api/b/userData/getDataCount', 
        'method':'POST',
        'headers':{ "Content-Type":"application/json"},
        'body':o,
      }).then(res => {
        console.info('埋点数据请求结果=====》',res)

        //数据类展示
        this.orderLevel(query.orderLevel);

        this.setData({
          seeData:res.data
        })

      })

    }else{

      // getApp().cloud.application.httpRequest({
      //   'path' : '/api/b/getAppName', 
      //   'method':'GET',
      //   'headers':{ "Content-Type":"application/json"},
      //   'body':{},
      // }).then(res => {

      //   this.setData({
      //     option:res.data
      //   })

      //   // this.setData({
      //   //   activityId:res.data[0].id
      //   // })

      //   // this.reqSeeData();

      //   //判断版本orderLevel
      //   this.orderLevel(res.data[0].orderLevel);
        
      //   console.log("活动列表",res)

      // })
      

    }

    //this.getActiveLise();

  },
	
	onShow(){
    // this.reqSeeData();
    
		this.getActiveLise(this.data.dataSeeId);
	},
});
